package com.iscreen.dbupgrade.operations;

import com.iscreen.dbupgrade.DBUpgrade;
import com.iscreen.dbupgrade.objects.Command;
import com.iscreen.dbupgrade.queries.QueryFactory;
import com.iscreen.dbupgrade.queries.UpgradeQuery;

public abstract class UpgradeCommand extends UpgradeOperation
{

	private final long id;
	private final UpgradeStep parentStep;
	protected final UpgradeQuery upgradeQuery;

	protected final QueryFactory queryFactory = DBUpgrade.getInstance().getFactory().getQueryFactory();
	
	protected abstract UpgradeQuery getUpgradeQuery(Command command);
	
	protected UpgradeCommand(Command command, UpgradeStep parentStep)
	{
		this.id = command.getId();
		this.parentStep = parentStep;
		this.upgradeQuery = getUpgradeQuery(command);
		this.connection = parentStep.getConnection();
	}

	@Override
	public long getCommandId()
	{
		return id;
	}

	@Override
	public long getStepId()
	{
		return parentStep.getStepId();
	}

	@Override
	public String getSql()
	{
		return upgradeQuery.getSql();
	}
}
